//
//  Team9DesignHederImageView.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/19.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9DesignHederImageView.h"
#import "Team9Header.h"
#import "Team9JQHeader.h"


@interface Team9DesignHederImageView ()
@property(nonatomic, strong) UIImageView *myImageView;
@property(nonatomic, strong) UILabel *styleLabel;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UIImageView *faceImageView;
@property(nonatomic, strong) UILabel *typeLabel;

@property(nonatomic, strong) UILabel *commentLabel;
@property(nonatomic, strong) UIImageView *commentImageView;
@property(nonatomic, strong) UILabel *likeLabel;
@property(nonatomic, strong) UIImageView *likeImageView;
@property(nonatomic, strong) UILabel *viewLabel;
@property(nonatomic, strong) UIImageView *viewImageView;


@end
@implementation Team9DesignHederImageView


- (instancetype)init{
    self = [super init];
    if (self) {
        [self createView];
//        [self test];
    }
    return self;
}
- (void)test{
    self.myImageView.image = [UIImage imageNamed:@"test"];
    self.faceImageView.backgroundColor = [UIColor yellowColor];
    self.titleLabel.text = @"123";
    self.styleLabel.text = @"123";
    self.viewLabel.text = @"15";
    self.likeLabel.text = @"2";
    self.commentLabel.text = @"4";
}
- (void)createView{
    self.myImageView = [UIImageView new];
    [self addSubview:_myImageView];
    
    self.styleLabel = [UILabel new];
    [self addSubview:_styleLabel];
    self.styleLabel.font = [UIFont systemFontOfSize:20 * WIDTH / 375];
    
    self.titleLabel = [UILabel new];
    [self addSubview:_titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:16 * WIDTH / 375];
    
    self.nameLabel = [UILabel new];
    [self addSubview:_nameLabel];
    self.nameLabel.font = [UIFont systemFontOfSize:14 * WIDTH / 375];
    
    self.faceImageView = [UIImageView new];
    [self addSubview:_faceImageView];
    
    self.typeLabel = [UILabel new];
    [self addSubview:_typeLabel];
    self.typeLabel.backgroundColor = [UIColor magentaColor];
    self.typeLabel.font = [UIFont systemFontOfSize:12 * WIDTH / 375];
    

    self.commentLabel = [UILabel new];
    [self addSubview:_commentLabel];
    self.commentLabel.font = [UIFont systemFontOfSize:12 * WIDTH / 375];
    
    self.commentImageView = [[UIImageView alloc] init];
    [self addSubview:_commentImageView];
    
    self.likeLabel = [UILabel new];
    self.likeLabel.font = [UIFont systemFontOfSize:12 * WIDTH / 375];
    [self addSubview:_likeLabel];
    
    self.likeImageView = [[UIImageView alloc] init];
    [self addSubview:_likeImageView];
    
    self.viewLabel = [UILabel new];
    self.viewLabel.font = [UIFont systemFontOfSize:12 * WIDTH / 375];
    [self addSubview:_viewLabel];
    
    self.viewImageView = [[UIImageView alloc] init];
    [self addSubview:_viewImageView];
    
    
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel *label = (UILabel *)view;
            label.textColor = [UIColor whiteColor];
        }
    }
    
    self.faceImageView.layer.masksToBounds = YES;
    self.faceImageView.layer.cornerRadius = 20 * WIDTH / 375;
//    [self p_contraints];
    self.commentImageView.image = [UIImage imageNamed:@"3-comment"];
    self.likeImageView.image = [UIImage imageNamed:@"3-like"];
    self.viewImageView.image = [UIImage imageNamed:@"3-view"];
}
- (void)p_contraints{
    [self.myImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.equalTo(self);
        make.height.equalTo(@(WIDTH / 375 * 300));
    }];
//    self.styleLabel.numberOfLines = 0;
    [self.styleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.titleLabel.mas_top).offset(-20);
        make.centerX.equalTo(self);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.myImageView);
    }];
    
    [self.faceImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.myImageView).offset(10);
        make.bottom.equalTo(self.myImageView).offset(-10);
        make.width.height.equalTo(@(40 * WIDTH / 375));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.faceImageView.mas_right).offset(10);
        make.centerY.equalTo(self.faceImageView);
    }];
    
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
        make.centerY.equalTo(self.nameLabel);
    }];
    
    
    [self.commentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-10);
        make.centerY.equalTo(self.faceImageView);
    }];
    [self.commentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.commentLabel.mas_left).offset(-5);
        make.centerY.equalTo(self.faceImageView);
        make.width.height.equalTo(@(12 * WIDTH / 375));
    }];
    [self.likeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.commentImageView.mas_left).offset(-10);
        make.centerY.equalTo(self.faceImageView);
        ;
    }];
    [self.likeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.likeLabel.mas_left).offset(-5);
        make.centerY.equalTo(self.faceImageView);
        make.width.height.equalTo(@(12 * WIDTH / 375));
    }];
    [self.viewLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.likeImageView.mas_left).offset(-10);
        make.centerY.equalTo(self.faceImageView);
    }];
    [self.viewImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.viewLabel.mas_left).offset(-5);
        make.centerY.equalTo(self.faceImageView);
        make.width.height.equalTo(@(12 * WIDTH / 375));
    }];
}

- (void)setModel:(Team9ExpertCollection_infoModel *)model{
    if ( _model != model) {
        _model = model;
    }
    self.nameLabel.text = _model.author_nick;
    self.titleLabel.text = _model.title_sub_3;
    self.styleLabel.text = _model.col_name;
//    NSLog(@"pic = %@", self.model.cover);
    if (![self.model.cover isEqualToString:@""]) {
        [Team9Tool sd_imageView:self.myImageView image:self.model.cover placeholderImage:@"111"];
    } else self.myImageView.image = [UIImage imageNamed:@"111"];
    [Team9Tool sd_imageView:self.faceImageView image:self.model.author_face placeholderImage:@"333"];
    
    switch (self.model.author_type.intValue) {
        case 0:
            self.typeLabel.text = @"";
            break;
        case 1:
            self.typeLabel.text = @"设计师";
            break;
        case 2:
            self.typeLabel.text = @"工长";
            break;
        default:
            break;
    }
    self.viewLabel.text = [NSString stringWithFormat:@"%d", self.model.view_count.intValue];
    self.likeLabel.text = [NSString stringWithFormat:@"%d", self.model.like_count.intValue];
    self.commentLabel.text = [NSString stringWithFormat:@"%d", self.model.comment_count.intValue];
    [self p_contraints];
    
    [Team9Tool imageView:self.faceImageView type:self.model.author_type Id:self.model.author_id viewController:_vc];
}
@end
